package com.ikangtai.shecare.stickycalendar.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.util.AppLog;
import com.ikangtai.shecare.stickycalendar.fragment.widget.GroupButtonView;
import com.ikangtai.shecare.stickycalendar.http.MucusHttp;
import com.ikangtai.shecare.stickycalendar.http.util.MucusMsg;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangling on 16/9/8.
 */
public class MusListAdapter extends BaseAdapter {
    private ViewHolder viewHolder;
    private Context mContext;
    private List<String> mListBeen;

    private int mucusStatus;
    private int mucusFlow;
    private int mucusColor;
    private List<MucusMsg> mucusMsgList = new ArrayList<MucusMsg>();
    private MucusMsg mucusMsg = new MucusMsg();

    public MusListAdapter(Context mContext, List<String> mListBeen) {
        this.mContext = mContext;
        this.mListBeen = mListBeen;
    }


    @Override
    public int getCount() {
        return mListBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return mListBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder = new ViewHolder();
        LayoutInflater inflater = LayoutInflater.from(mContext);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout
                    .mus_described, null);

            viewHolder.item1 = (GroupButtonView) convertView.findViewById(R.id.mus_item1);
            viewHolder.item2 = (GroupButtonView) convertView.findViewById(R.id.mus_item2);
            viewHolder.item3 = (GroupButtonView) convertView.findViewById(R.id.mus_item3);
            viewHolder.saveMucus = (ImageView) convertView.findViewById(R.id.header_view_save);

            viewHolder.item1.setOnGroupBtnClickListener(new GroupButtonView.OnGroupBtnClickListener() {
                @Override
                public void groupBtnClick(String code) {
                    AppLog.i("wzz----code----1---" + code);
                    mucusMsg.setMucusStatus(Integer.parseInt(code));
                }
            });

            viewHolder.item2.setOnGroupBtnClickListener(new GroupButtonView.OnGroupBtnClickListener() {
                @Override
                public void groupBtnClick(String code) {
                    AppLog.i("wzz----code----2---" + code);
                    mucusMsg.setMucusFlow(Integer.parseInt(code));
                }
            });
            viewHolder.item3.setOnGroupBtnClickListener(new GroupButtonView.OnGroupBtnClickListener() {
                @Override
                public void groupBtnClick(String code) {
                    AppLog.i("wzz----code----3---" + code);
                    mucusMsg.setMucusColor(Integer.parseInt(code));
                }
            });
            viewHolder.saveMucus.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mucusMsg.setDateRecord("2016-08-18");
                    mucusMsgList.add(mucusMsg);
                    MucusHttp mucusHttp = new MucusHttp(mContext, mucusMsgList);
                    mucusHttp.saveSelectedDayRecord();
                }
            });

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        return convertView;
    }


    static class ViewHolder {

        private GroupButtonView item1, item2, item3;
        private ImageView saveMucus;

    }
}
